<?php
/*
Plugin Name: Slickr sidebar widget
Description: Adds a sidebar widget to display your Flickr photos
Author: Joe Tan, Rupert Morris
Version: 0.1b
Author URI: http://www.stimuli.ca/slickr/
*/

class SlickrWidget {
    function SlickrWidget () {
        if (function_exists('register_sidebar_widget')) {
            register_sidebar_widget('Flickr Sidebar', array(&$this, 'display'));
            register_widget_control('Flickr Sidebar', array(&$this, 'control'));
        }
    }
    
    function control() {
		$options = $newoptions = get_option('Slickr_flickr_widget');
		if ( $_POST['Slickr-flickr-submit'] ) {
			$newoptions['title'] = strip_tags(stripslashes($_POST['Slickr-flickr-title']));
			$newoptions['tags'] = strip_tags(stripslashes($_POST['Slickr-flickr-tags']));
			$newoptions['count'] = (int) $_POST['Slickr-flickr-count'];
		}
		if ( $options != $newoptions ) {
			$options = $newoptions;
			update_option('Slickr_flickr_widget', $options);
		}

        include(dirname(__FILE__).'/widget-options.html');
    }
    
    function display($args) {
        global $SlickrPlugin;
		
        extract($args);
        $defaults = array('count' => 10);
        $options = (array) get_option('Slickr_flickr_widget');
        foreach ( $defaults as $key => $value )
			if ( !isset($options[$key]) )
				$options[$key] = $defaults[$key];
		$photos = $SlickrPlugin->getRecentPhotos($options['tags'], 0, $options['count']);
		echo $before_widget;
        include(dirname(__FILE__).'/widget-display.html');
        echo $after_widget;
    }
    
}
$SlickrWidget =& new SlickrWidget();
?>
